/*!
    \copyright  Copyright (c) 2022 - 2025 Qualcomm Technologies International, Ltd.
                All Rights Reserved.
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \addtogroup le_audio_client
    @{
    \brief      Private types and functions for LE Audio Client broadcast
*/

#ifndef LE_AUDIO_CLIENT_BROADCAST_PRIVATE_H_
#define LE_AUDIO_CLIENT_BROADCAST_PRIVATE_H_

#ifdef INCLUDE_LE_AUDIO_BROADCAST_SOURCE

#include "le_audio_client_broadcast_router.h"
#include "le_audio_client_audio_config.h"

#define LE_AUDIO_CLIENT_BROADCAST_MAX_SET_MEMBERS           (2u)

/*! \brief Various broadcast audio configuration types */
typedef enum
{
    /*! Broadcast audio configuration type is not known or invalid */
    LE_AUDIO_CLIENT_BROADCAST_CONFIG_INVALID,

    /*! High quality broadcast audio configuration */
    LE_AUDIO_CLIENT_BROADCAST_CONFIG_TYPE_HQ,

    /*! Todo: Add more configurations */
} le_audio_client_broadcast_config_type_t;

/*! \brief Structure to hold audio configuration information for broadcast */
typedef struct
{
    /*! Configuration type to use for broadcast */
    le_audio_client_broadcast_config_type_t config_type;

    /*! Total number of sub groups(non-zero) in the broadcast group */
    uint8                                   num_sub_group;

    /*! Length of Broadcast source name */
    uint8                                   broadcast_source_name_len;

    /*! Broadcast source name */
    const char                              *broadcast_source_name;

    /*! Broadcast code that has been set for streaming */
    const uint8                             *broadcast_code;

    /*! CapClientBcastType */
    uint16                                  broadcast_type;
    /*! Presentation delay to synchronize the presentation of multiple BISs in a BIG */
    uint32                                  presentation_delay;

    /*! Broadcast ID to use */
    uint32                                  broadcast_id;

    /*! BASE level Sub group related information */
    CapClientBigSubGroups                   *sub_group_info;

    /*! User set Broadcast config parameters */
    CapClientBcastConfigParamV1             broadcast_config_params;
} le_audio_client_audio_broadcast_config_t;

typedef struct
{
    /*! use case for the active session */
    uint16                                          audio_context;

    /*! Audio configuration using for broadcast */
    const le_audio_client_audio_broadcast_config_t *audio_config;

    /*! If TRUE, release all the underlying configuration */
    bool                                            release_config;

    /*! Sampling frequency for broadcast audio streaming */
    uint16                                          sampling_frequency;

    /*! Frame duration for broadcast audio streaming */
    uint8                                           frame_duration;

    /*! Octects per frame for broadcast audio streaming */
    uint16                                          octets_per_frame;

    /*! BIS handles for broadcast audio streaming */
    uint16                                          bis_handles[TMAP_BROADCAST_MAX_SUPPORTED_BIS];

    /* BIG transport latency reported for the given broadcast session */
    uint32                                          transport_latency_big;
} le_audio_broadcast_session_data_t;

/*! States that represents brs read req completed or not */
typedef enum
{
    le_audio_broadcast_brs_state_not_initialized,
    le_audio_broadcast_brs_state_initialized,
} le_audio_client_broadcast_brs_read_state_t;

/*! \brief Set member specific info */
typedef struct
{
    /*! Flag to denote whether current source is pa synced */
    bool             is_current_source_pa_synced;

    /*! Flag to denote whether we need to remove/modify the source before adding new one */
    bool             is_current_source_to_be_removed;

    /*! Flag to denote source have been added to assistant or not */
    bool             is_source_added_to_assistant;

    /*! Brs read state */
    le_audio_client_broadcast_brs_read_state_t   brs_read_state;

    /*! Currently active source ID */
    uint8            source_id;

    /*! Gatt cid */
    gatt_cid_t           cid;
} le_audio_client_broadcast_set_member_state_info_t;

/*! \brief Information related to the source adding to the assistant */
typedef struct
{
    /*! Advertising SID */
    uint8            adv_sid;

    /*! Advertising handle for PA */
    uint8            adv_handle;

    /*! Broadcast Identifier */
    uint32           broadcast_id;

    /*! Bitmasked bis_index */
    uint32           bis_index;

    /*! Set member specific state info*/
    le_audio_client_broadcast_set_member_state_info_t src_info[LE_AUDIO_CLIENT_BROADCAST_MAX_SET_MEMBERS];
} le_audio_broadcast_asst_src_param_t;

/*! \brief Initialise LE audio client broadcast */
void leAudioClientBroadcast_Init(void);

/*! \brief Start broadcast streaming */
bool leAudioClientBroadcast_StartStreaming(uint16 audio_context);

/*! \brief Stop broadcast streaming */
bool leAudioClientBroadcast_StopStreaming(bool remove_config);

/*! \brief Set the broadcast audio configuration type to use */
void leAudioClient_SetBroadcastAudioConfigType(le_audio_client_broadcast_config_type_t config_type);

/*! \brief Returns the broadcast audio configuration for the curent configuration type  */
const le_audio_client_audio_broadcast_config_t* leAudioClient_GetBroadcastAudioConfig(void);

/*! \brief Returns the broadcast advertisement configuration for the currently set broadcast type  */
void leAudioClient_GetBroadcastAdvConfig(CapClientBcastSrcAdvParams *bcast_adv_settings);

#ifdef INCLUDE_LE_AUDIO_UNICAST_SOURCE

/*! \brief Add the source to assistant if not added already */
void leAudioClientBroadcast_AddSourceToAssistant(void);

#else /* INCLUDE_LE_AUDIO_UNICAST_SOURCE */

#define leAudioClientBroadcast_AddSourceToAssistant()

#endif /* INCLUDE_LE_AUDIO_UNICAST_SOURCE */

/*! \brief Store broadcast streaming Parameters*/
void leAudioClientBroadcast_StoreAudioParams(const LEA_CLIENT_INTERNAL_BCAST_SRC_STREAM_START_CFM_T *stream_params);

/*! Get the Sample rate from BAP sampling frequency */
uint16 leAudioClientBroadcast_GetSampleRate(uint16 bap_sampling_freq);

/*! \brief Resets all information related to broadcast source */
void leAudioClientBroadcast_ResetSourceContext(void);

/*! \brief Process the message if message is from broadcast router. Return TRUE if message
           is processed. FALSE otherwise
 */
bool leAudioClientBroadcast_ProcessMsgIfFromBcastRouter(MessageId id, Message message);

/*! \brief Verify if all the needed callback functions are registered from the application
*/
void leAudioClientBroadcast_VerifyClientRegistration(void);

#else /* INCLUDE_LE_AUDIO_BROADCAST_SOURCE */

#define leAudioClientBroadcast_Init()
#define leAudioClientBroadcast_ResetSourceContext()
#define leAudioClientBroadcast_AddSourceToAssistant()
#define leAudioClientBroadcast_ProcessMsgIfFromBcastRouter(id, message) (FALSE)
#define leAudioClientBroadcast_VerifyClientRegistration()

#endif /* INCLUDE_LE_AUDIO_BROADCAST_SOURCE */

#endif /* LE_AUDIO_CLIENT_BROADCAST_PRIVATE_H_ */

/*! @} */
